// OptionDlg.cpp : implementation file
//

#include "stdafx.h"
#include "aremoteserver.h"
#include "OptionDlg.h"
#include "Global.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COptionDlg dialog

IMPLEMENT_DYNCREATE(COptionDlg, CXTPPropertyPage)

COptionDlg::COptionDlg() : CXTPPropertyPage(COptionDlg::IDD)
{
	//{{AFX_DATA_INIT(COptionDlg)
	m_CommMode = -1;
	m_TimeDelay = 0;
	m_Port = 0;
	m_AutoStart = FALSE;
	//}}AFX_DATA_INIT
}


void COptionDlg::DoDataExchange(CDataExchange* pDX)
{
	CXTPPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COptionDlg)
	DDX_Radio(pDX, IDC_RADIO_TCP, m_CommMode);
	DDX_Text(pDX, IDC_EDIT_TIMEDELAY, m_TimeDelay);
	DDV_MinMaxInt(pDX, m_TimeDelay, 0, 1024);
	DDX_Text(pDX, IDC_EDIT_PORT, m_Port);
	DDX_Check(pDX, IDC_CHECK_AUTORUN, m_AutoStart);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COptionDlg, CXTPPropertyPage)
	//{{AFX_MSG_MAP(COptionDlg)
	ON_BN_CLICKED(IDC_RADIO_TCP, OnRadioTcp)
	ON_BN_CLICKED(IDC_RADIO_UDP, OnRadioUdp)
	ON_EN_CHANGE(IDC_EDIT_PORT, OnChangeEditPort)
	ON_EN_CHANGE(IDC_EDIT_TIMEDELAY, OnChangeEditTimedelay)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COptionDlg message handlers

void COptionDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	g_Global.g_IniFile.SetKeyInteger("Communication", "CommMode", m_CommMode);
	g_Global.g_IniFile.SetKeyInteger("Communication", "Port", m_Port);
	g_Global.g_IniFile.SetKeyInteger("Display", "ScreenTipShowTime", m_TimeDelay);
	g_Global.g_IniFile.SetKeyInteger("Base", "AutoStart", m_AutoStart);
	g_Global.SetAutoStart(m_AutoStart);
	CXTPPropertyPage::OnOK();
}

BOOL COptionDlg::OnInitDialog() 
{
	CXTPPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_CommMode = g_Global.g_IniFile.GetKeyInteger("Communication", "CommMode", DEFAULT_COMM_MODE);
	m_Port = g_Global.g_IniFile.GetKeyInteger("Communication", "Port", DEFAULT_COMM_PORT);
	m_TimeDelay = g_Global.g_IniFile.GetKeyInteger("Display", "ScreenTipShowTime", 3);
	m_AutoStart = g_Global.g_IniFile.GetKeyInteger("Base", "AutoStart", 0);
	UpdateData(FALSE);
	UpdateCtrl();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void COptionDlg::OnRadioTcp() 
{
	// TODO: Add your control notification handler code here
	UpdateCtrl();
	SetModified(TRUE);
}

void COptionDlg::OnRadioUdp() 
{
	// TODO: Add your control notification handler code here
	UpdateCtrl();
	SetModified(TRUE);
}

void COptionDlg::UpdateCtrl()
{
	UpdateData(TRUE);
}

void COptionDlg::OnChangeEditPort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CXTPPropertyPage::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	SetModified(TRUE);
}

void COptionDlg::OnChangeEditTimedelay() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CXTPPropertyPage::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	SetModified(TRUE);
}
